#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
//#define int long long
using namespace std;
const int N=1e6+5;
const int M=1e3+5;
int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
void print(int x){
	if(x<0)putchar('-'),x=-x;
	if(x<10){
		putchar(x+'0');
		return;
	}
	print(x/10);
	putchar(x%10+'0');
}
int n=7,m,k;
int T;
char c[M][M];
int x=4,y=4;
int xx,yy;
void move(){
	char h=getch();
	c[x][y]='.';
	if(h=='w'&&x-1>=1&&c[x-1][y]=='.')x--;
	else if(h=='a'&&y-1>=1&&c[x][y-1]=='.')y--;
	else if(h=='s'&&x+1<=n&&c[x+1][y]=='.')x++;
	else if(h=='d'&&y+1<=n&&c[x][y+1]=='.')y++;
	else move();
	c[x][y]='O';
}
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int man[4];
int zx,zy;
void Z(){
	c[xx][yy]='.';
	for(int i=0;i<4;i++){
		man[i]=1e9;
		int xxx=xx+dx[i];
		int yyy=yy+dy[i];
		if(xxx<1||yyy<1||xxx>n||yyy>n||c[xxx][yyy]=='#')continue;
		man[i]=abs(xxx-x)+abs(yyy-y);
	}
	int mni=0;
	for(int i=1;i<4;i++)if(man[i]<man[mni])mni=i;
	xx+=dx[mni];
	yy+=dy[mni];
	c[xx][yy]='Z';
}
void z(){
	c[zx][zy]='.';
	for(int i=0;i<4;i++){
		man[i]=1e9;
		int xxx=zx+dx[i];
		int yyy=zy+dy[i];
		if(xxx<1||yyy<1||xxx>n||yyy>n||c[xxx][yyy]=='#')continue;
		man[i]=abs(xxx-x)+abs(yyy-y);
	}
	int mni=0;
	for(int i=1;i<4;i++)if(man[i]<man[mni])mni=i;
	zx+=dx[mni];
	zy+=dy[mni];
	c[zx][zy]='z';
}
signed main(){
	//ios::sync_with_stdio(0);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			c[i][j]='.';
		}
	}
	for(int i=1;i<=n;i++)c[1][i]=c[i][1]=c[n][i]=c[i][n]='#';
	int cnt=0;
	c[x][y]='O';
	xx=(rand()-1)%n+1;
	yy=(rand()-1)%n+1;
	while((xx==4&&yy==4)||c[xx][yy]=='#'){
		xx=(rand()-1)%n+1;
		yy=(rand()-1)%n+1;
	}
	c[xx][yy]='Z';
	zx=(rand()-1)%n+1;
	zy=(rand()-1)%n+1;
	while(c[zx][zy]!='.'){
		zx=(rand()-1)%n+1;
		zy=(rand()-1)%n+1;
	}
	c[zx][zy]='z';
	while(1){
		system("cls");
		cout<<"now: "<<cnt++<<'\n';
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		move();
		system("cls");
		cout<<"now: "<<cnt++<<'\n';
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		move();
		system("cls");
		cout<<"now: "<<cnt++<<'\n';
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		Z();
		Sleep(1000);
		system("cls");
		cout<<"now: "<<cnt++<<'\n';
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		if(xx==x&&yy==y)break;
		z();
		Sleep(1000);
		system("cls");
		cout<<"now: "<<cnt++<<'\n';
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<c[i][j];
			}
			cout<<'\n';
		}
		if(zx==x&&zy==y)break;
	}
}

